// pages/gatherHouse/addHouseMethod/addHouseMethod.js
import p from '../../../utils/platform'
import { insertHouseLog } from '../../../common/log'
import constant from '../../../common/constant'
const app = getApp()
Page({
  
  /**
   * 页面的初始数据
   */
  data: {
    model: [{
        name: constant.ER_SHOU,
        title: "添加二手",
        icon: "../images/es.png",
        url: "/pages/addHouse/chooseHouse/chooseHouse",
        fn: () => {
          wx.setStorageSync('currentStatus', 1)
        }
      },
      {
        name: constant.CHU_ZU,
        title: "添加出租",
        icon: "../images/cz.png",
        url: "/pages/addHouse/chooseHouse/chooseHouse",
        fn: () => {
          wx.setStorageSync('currentStatus', 2)
        }
      },
      {
        name: constant.XIN_FANG,
        title: "添加新房",
        icon: "../images/xf.png",
        url: "/pages/newBuildinghouse/increaseHouse/increaseHouse",
        fn: () => {
          wx.setStorageSync('currentStatus', 3)
        }
      },
      // {
      //   title: "房源搬家",
      //   icon: "../images/bj.png",
      //   url: "/pages/gatherHouse/selectWebsite/selectWebsite"
      // }
    ]
  },

  handleGo(e) {
    const index = e.currentTarget.dataset.index
    const data = this.data.model[index]
    if (data.fn) {
      data.fn()
    }
    p.redirectTo({
      url: data.url
    })

    wx.gio('track', constant.ADD_ROOM, {
      [constant.ROOMTYPE_VAR]: data.name,
    })
  },

  handleClose() {
    if (getCurrentPages().length > 1) {
      p.navigateBack()
    } else {
      p.reLaunch({ url: '/pages/index/index' })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    app.mobileLogin(true)
      .then(() => {
        insertHouseLog({
          logType: "0",
        })
      })
      .catch(() => {
        p.redirectTo({
          url: "/pages/startPage/startPage"
        })
        app.globalData.afterMobileAuthorCallBack = () => {
          p.redirectTo({
            url: "/pages/gatherHouse/addHouseMethod/addHouseMethod"
          })
        }
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
})